package com.atguigu.daijia.customer.service.impl;

import com.atguigu.daijia.coupon.client.CouponFeignClient;
import com.atguigu.daijia.customer.service.CouponService;
import com.atguigu.daijia.model.vo.base.PageVo;
import com.atguigu.daijia.model.vo.coupon.AvailableCouponVo;
import com.atguigu.daijia.model.vo.coupon.NoReceiveCouponVo;
import com.atguigu.daijia.model.vo.coupon.NoUseCouponVo;
import com.atguigu.daijia.model.vo.coupon.UsedCouponVo;
import com.atguigu.daijia.model.vo.order.OrderBillVo;
import com.atguigu.daijia.order.client.OrderInfoFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class CouponServiceImpl implements CouponService {

	@Autowired
	private CouponFeignClient couponFeignClient;

	@Autowired
	private OrderInfoFeignClient orderInfoFeignClient;

	//优惠券活动接口管理
	@Override
	public PageVo<NoReceiveCouponVo> findNoReceivePage(Long customerId, Long page, Long limit) {
		return couponFeignClient.findNoReceivePage(customerId, page, limit).getData();
	}

	//查询未使用优惠券分页列表
	@Override
	public PageVo<NoUseCouponVo> findNoUsePage(Long customerId, Long page, Long limit) {
		return couponFeignClient.findNoUsePage(customerId, page, limit).getData();
	}

	//查询已使用优惠券分页列表
	@Override
	public PageVo<UsedCouponVo> findUsedPage(Long customerId, Long page, Long limit) {
		return couponFeignClient.findUsedPage(customerId, page, limit).getData();
	}

	//领取优惠券
	@Override
	public Boolean receive(Long customerId, Long couponId) {
		return couponFeignClient.receive(customerId, couponId).getData();
	}

	//获取未使用的最佳优惠券信息
	@Override
	public List<AvailableCouponVo> findAvailableCoupon(Long customerId, Long orderId) {
		OrderBillVo orderBillVo = orderInfoFeignClient.getOrderBillInfo(orderId).getData();
		return couponFeignClient.findAvailableCoupon(customerId, orderBillVo.getPayAmount()).getData();
	}
}
